package moduledefault.classify.committee.view.jpanel;

import java.util.ArrayList;
import java.util.List;
import moduledefault.classify.committee.Committee;
import moduledefault.classify.committee.FacadeCommitteeClassifierModule;

/**
 *
 * @author Administrador
 */
public class JPanelCommittee extends javax.swing.JPanel {

    private List<ClassifierModuleConfig> classifiers = new ArrayList<ClassifierModuleConfig>();
    //private ClassifierModuleInterface classifierModule = null;

    /**
     * Creates new form JPanelKnn
     */
    public JPanelCommittee() {
        initComponents();

        for (ClassifierModuleConfig classifierModuleConfig : FacadeCommitteeClassifierModule.getClassifiers()) {
            classifierModuleConfig.initConfig(classifiers.size(), jPanelClassifiers);
            classifiers.add(classifierModuleConfig);
        }
        jScrollPane1.doLayout();

        /*
         jComboBoxStructure.addItem("");
         for (ModuleAvailable<ClassifierModuleInterface> c : ModuleFactory.getArrayListClassifierModules()) {
         jComboBoxStructure.addItem(c);
         }        
         */

    }

    /**
     * This method is called from within the constructor to initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is always
     * regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {
        java.awt.GridBagConstraints gridBagConstraints;

        jLabelDistanceFunction = new javax.swing.JLabel();
        jComboBoxStructure = new javax.swing.JComboBox();
        jButtonCommit = new javax.swing.JButton();
        jScrollPane1 = new javax.swing.JScrollPane();
        jPanelClassifiers = new javax.swing.JPanel();
        jLabelDistanceFunction1 = new javax.swing.JLabel();
        jButtonAddClassifier = new javax.swing.JButton();

        jLabelDistanceFunction.setText("Classificadores");

        jComboBoxStructure.setModel(new javax.swing.DefaultComboBoxModel(Committee.STRUCTURE_FUNCTION));
        jComboBoxStructure.setSelectedItem(FacadeCommitteeClassifierModule.getStructureFunction());

        jButtonCommit.setText("Concluir");
        jButtonCommit.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButtonCommitActionPerformed(evt);
            }
        });

        jPanelClassifiers.setBorder(javax.swing.BorderFactory.createTitledBorder(""));
        jPanelClassifiers.setToolTipText("Um");
        jPanelClassifiers.setLayout(new java.awt.GridBagLayout());
        jScrollPane1.setViewportView(jPanelClassifiers);
        jPanelClassifiers.getAccessibleContext().setAccessibleName("");

        jLabelDistanceFunction1.setText("Estrutura");

        jButtonAddClassifier.setText("Adicionar Classificador");
        jButtonAddClassifier.setAlignmentY(0.0F);
        jButtonAddClassifier.setCursor(new java.awt.Cursor(java.awt.Cursor.DEFAULT_CURSOR));
        jButtonAddClassifier.setDisplayedMnemonicIndex(0);
        jButtonAddClassifier.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButtonAddClassifierActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(this);
        this.setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(layout.createSequentialGroup()
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                            .addComponent(jLabelDistanceFunction)
                            .addComponent(jLabelDistanceFunction1))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(jButtonAddClassifier)
                            .addComponent(jComboBoxStructure, javax.swing.GroupLayout.PREFERRED_SIZE, 213, javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addContainerGap(296, Short.MAX_VALUE))
                    .addGroup(layout.createSequentialGroup()
                        .addComponent(jScrollPane1)
                        .addContainerGap())))
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addComponent(jButtonCommit)
                .addContainerGap())
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jComboBoxStructure, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jLabelDistanceFunction1))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jButtonAddClassifier)
                    .addComponent(jLabelDistanceFunction))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jScrollPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 135, Short.MAX_VALUE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jButtonCommit)
                .addContainerGap())
        );
    }// </editor-fold>//GEN-END:initComponents

    private void jButtonCommitActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButtonCommitActionPerformed
        commit();
    }//GEN-LAST:event_jButtonCommitActionPerformed

    private void jButtonAddClassifierActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButtonAddClassifierActionPerformed
        addClassifier();
    }//GEN-LAST:event_jButtonAddClassifierActionPerformed
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton jButtonAddClassifier;
    private javax.swing.JButton jButtonCommit;
    private javax.swing.JComboBox jComboBoxStructure;
    private javax.swing.JLabel jLabelDistanceFunction;
    private javax.swing.JLabel jLabelDistanceFunction1;
    private javax.swing.JPanel jPanelClassifiers;
    private javax.swing.JScrollPane jScrollPane1;
    // End of variables declaration//GEN-END:variables

    private void commit() {
        //FacadeCommitteeClassifierModule.setStrucureFunction(Integer.parseInt(jTextFieldK.getText()));
        FacadeCommitteeClassifierModule.setStructureFunction((String) jComboBoxStructure.getSelectedItem());
        FacadeCommitteeClassifierModule.setClassifiers(classifiers);
        //FacadeCommitteeClassifierModule.setInferenceRule((String)jComboBoxInferenceRule.getSelectedItem());
        FacadeCommitteeClassifierModule.getJDialogConfig().dispose();
    }

    private void addClassifier() {

        ClassifierModuleConfig classifierModuleConfig = new ClassifierModuleConfig();
        classifierModuleConfig.initConfig(classifiers.size(), jPanelClassifiers);

        classifiers.add(classifierModuleConfig);
        jScrollPane1.doLayout();

    }
}
